package pl.skubicha.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import pl.skubicha.domain.FinalGrades;

public interface FinalGradesRepository extends JpaRepository< FinalGrades, Integer > {

	public final static String FIND_ALL_GRADES_FOR_SUBJECT_IN_GROUP_QUERY = "SELECT g FROM FinalGrades g JOIN g.users u JOIN g.subjects s WHERE s.id = :subjectID AND u.groups.id = :groupID";
	public final static String FIND_ALL_GRADES_FOR_USER_QUERY = "SELECT g FROM FinalGrades g WHERE g.users.id = :id AND g.subjects.id = :subjectID";

	@Query( FIND_ALL_GRADES_FOR_SUBJECT_IN_GROUP_QUERY )
	public List< FinalGrades > findAllGradesForSubjectInGroup( @Param( "subjectID" ) Integer idSubject, @Param( "groupID" ) Integer idGroup );

	@Query( FIND_ALL_GRADES_FOR_USER_QUERY )
	public List< FinalGrades > findAllGradesForUser( @Param( "id" ) Integer id, @Param( "subjectID" ) Integer idSubject );

}
